package com.xnyzc.lhy.finance.utils;

import com.xnyzc.lhy.common.exception.PangException;
import com.xnyzc.lhy.common.penum.EErrorCode;
import com.xnyzc.lhy.common.util.CheckUtil;

/**
 * 操作工具类
 * @author cuixiaojian
 */
public class HiddenUtil {

    private HiddenUtil() {};

    /**
     * 名去姓
     * @param name 人名
     * @return String
     */
    public static String nameBuffer(String name) {

        if (CheckUtil.objIsEmpty(name)) {
            throw PangException.create(EErrorCode.notFoundYourName);
        }

        StringBuffer nameBuffer = new StringBuffer();
        nameBuffer.append("*");
        if (name.length() == 2) {
            nameBuffer.append(name.substring(name.length() - 1));
        } else if (name.length() >= 3) {
            nameBuffer.append(name.substring(name.length() - 2));
        }

        return nameBuffer.toString();
    }

    /**
     * 身份证截取头尾数字返回
     * @param identity 身份证号
     * @return String
     */
    public static String indntityBuffer(String identity) {

        if (CheckUtil.objIsEmpty(identity)) {
            throw PangException.create(EErrorCode.notFoundYourIdentity);
        }

        StringBuffer identityBuffer = new StringBuffer();
        identityBuffer.append(identity.substring(0, 1));
        identityBuffer.append("****************");
        identityBuffer.append(identity.substring(identity.length() - 1));

        return identityBuffer.toString();
    }

    /**
     * 截取银行卡后四位返回
     * @param bankCardNumber 银行卡号
     * @return String
     */
    public static String bankCardBuffer(String bankCardNumber) {

        if (CheckUtil.objIsEmpty(bankCardNumber)) {
            throw PangException.create(EErrorCode.notFoundYourBankCardNumber);
        }

        return bankCardNumber.substring(bankCardNumber.length() - 4, bankCardNumber.length());
    }

}
